;2008-05-20
;Av Benjamin Ingberg och Patrik Johansson
;
;Evilballons styrfil, ärver rättigheter från monster, innehåller animationer för evilballon 
;samt hur den skall röra sig i världen

(load "monster.scm")

(define *evilballoon-sprites*
  (list (cons 'default "./sprites/evilballoon/balloon2.gif")
        (cons 'default "./sprites/evilballoon/balloon1.gif")
        (cons 'default "./sprites/evilballoon/balloon3.gif")
        (cons 'default "./sprites/evilballoon/balloon1.gif")))

(define evilballoon%
  (class monster%
    (init x y)
    
    (super-new [x x][y y][w 48][h 48][sprites *evilballoon-sprites*])
    
    (define action-counter -1)
    (define current-action #f)
    
    (define/override (die board)
      (send *board* add-world-object
            (new evilballoon-death%
                 [x (send this get-x)]
                 [y (send this get-y)]
                 [board board])))
    
    (define/override (update board)
      (set! action-counter (- action-counter 1))
      (if (> action-counter 0)
          (do-action current-action board)
          (begin (set! action-counter (+ 20 (random 60)))
                 (let ((rand (random 4)))
                   (cond ((eq? rand 0) (set! current-action 'left)))
                   (cond ((eq? rand 1) (set! current-action 'right)))
                   (cond ((eq? rand 2) (set! current-action 'up)))
                   (cond ((eq? rand 3) (set! current-action 'down))))
                 (do-action current-action board))))
    
    (define/public (do-action action board)
      (let ((x (send this get-x))
            (y (send this get-y)))
      (cond ((eq? action 'left) (send this 
                                      try-move
                                      (- x 2)
                                      y
                                      board))
            ((eq? action 'right) (send this
                                       try-move
                                       (+ x 2)
                                       y
                                       board))
            ((eq? action 'up) (send this 
                                    try-move
                                    x
                                    (- y 2)
                                    board))
            ((eq? action 'down) (send this
                                      try-move
                                      x
                                      (+ y 2)
                                      board)))))
    
    (define draw-counter (random 100))
    (define (draw-out-sprite n)
      (define (draw-sprite-helper n list)
        (cond ((null? list) (void))
              ((= n 0) (draw-sprite-square (cdr (car list))
                                           (send this get-x)
                                           (send this get-y)
                                           (send this get-w)
                                           (send this get-h)))
              (else (draw-sprite-helper (- n 1) (cdr list)))))
      (draw-sprite-helper n (send this get-sprites)))
    
    (define/override (draw)
      (set! draw-counter (+ draw-counter 1))
      (draw-out-sprite (remainder (quotient draw-counter 10) 4)))))
;Ritar ut evilballon med olika sprites, så att han ser mer levande ut när han jagar schemerman